package com.cdcas;

@Action("com.cdcas.RadioChannel")
public class Mesage {
    private IChannel channel;

    @Instance("com.cdcas.Factory")
    public Mesage() {
        Action actionAnno = super.getClass().getAnnotation(Action.class);

        Instance instanceAnno = null;
        try {
            instanceAnno = super.getClass().getConstructor().getAnnotation(Instance.class);
            String factoryClassname = instanceAnno.value();
            Class<?> factoryClazz = Class.forName(factoryClassname);
            this.channel = (IChannel) factoryClazz.getMethod("getInstance",String.class).invoke(null,actionAnno.value());
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
    public String echo(String msg) throws Exception {
        String echoMsg = "消息发送失败";
        if (this.channel.build()) {
            echoMsg = "发送-------" + msg;
            this.channel.close();
        }
        return echoMsg;
    }
}
